/**
 * 热力图
 */
/* 参数示例
 data{
   id:'',
   name:'',
   radius:'',
   showThumbnails:false,
   data:[
     [ lat, lng, intensity],
     ...
   ]
 }
*/
import sgisLayerBase from '../../sgis.layer.base';
import styleModify from './echarts.stylemodify'; // 设置图层的可见性，透明度，zIndex文件
export default {
  activeMap: {}, // 当前活动地图
  heatLayer: {},
  heatLayerInfo: {}, // 图层其他相关信息
  /**
   * 创建地图折形图专题图
   */
  createLayer(map, data) {
    if (!map) {
      return;
    }
    if (!data) {
      return;
    }
    this.activeMap = map;
    this.heatLayer = L.heatLayer(data.data, {
      radius: data.radius ? data.radius : 30,
      minOpacity: 0.5,
      pane: styleModify.pane
    }).addTo(map);
    this.heatLayer.setOpacity = this.setOpacity; // 设置图层透明度
    this.heatLayer.setVisible = this.setVisible; // 设置图层可见性
    this.heatLayer.setZIndexOffset = this.setZIndexOffset; // 设置调整图层顺序函数;
    this.heatLayer._canvas.style.zIndex = styleModify.curZindex; // 为设置图层顺序调整特意设置
    const layerId = "heat_chart_" + data.id + "_" + +new Date();
    this.heatLayer.layerId = layerId;
    styleModify.layerOrder[layerId] = styleModify.curZindex;
    styleModify.curZindex -= 1;
    const heatLayerInfo = {
      layer: this.heatLayer,
      layerId,
      name: data.name,
      type: "heat",
      show: data.showThumbnails !== false,
      html: this.calGraph(layerId)
      // otherLayer: initLayer
    };
    this.heatLayerInfo = heatLayerInfo;
    sgisLayerBase.setOverLayers(this.heatLayerInfo);
    return this.heatLayerInfo;
  },
  /* *
   * 计算图例样式
   */
  calGraph(layerId) {
    const html = `
      <div style = 'width:90px;height:90px;line-height:90px;text-align:center;padding:20px;padding-left:35px;' class=${layerId}>
        <div style = 'width:60px;height:60px;background:radial-gradient(circle, red, yellow,GreenYellow,purple);border-radius:60px'> </div>
      </div>
    `;
    return html;
  },
  /**
   * 设置图层透明度
   * @param {*} opacity number
   */
  setOpacity(opacity) {
    this._canvas.style.opacity = opacity;
  },
  /**
   * 设置图层可见性
   * @param {string}  visible hidden/visible
   */
  setVisible(visible) {
    this._canvas.style.visibility = visible;
  },
  /** 设置调整图层顺序函数*/
  setZIndexOffset(index) {
    styleModify.setZIndexOffset(index, this.layerId, this._canvas);
  }
};
